<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<link href="style/editor.css" rel="stylesheet" type="text/css">
<script>
  var sLangDir=parent.oUtil.langDir;
  document.write("<scr"+"ipt src='language/"+sLangDir+"/search.js'></scr"+"ipt>");
</script>
<script>writeTitle()</script>
<script>
function bodyOnLoad()
  {

  loadTxt();

  var oEditor=parent.oUtil.oEditor;
  oEditor.focus();
  inpSearch.focus();
  }
function doSearch()
  {
  parent.oUtil.obj.setFocus();
  if(!parent.oUtil.obj.checkFocus()){return;}//Focus stuff
  var oEditor=parent.oUtil.oEditor;
  var oSel=oEditor.document.selection.createRange();

  if(chkMatchCase.checked && chkMatchWord.checked) sType=6;
  else if(chkMatchCase.checked) sType=4;
  else if(chkMatchWord.checked) sType=2;
  else sType=0;
  oSel.collapse(false)
  if(oSel.findText(inpSearch.value,1000000000,sType)) oSel.select();
  else
    {
    if(confirm(getTxt("Finished searching")))
      {
      oSel.expand("textedit");
      oSel.collapse("true");
      oSel.select();
      doSearch();
      }
    }
  parent.oUtil.obj.bookmarkSelection();
  parent.realTime(parent.oUtil.oName);
  }
function doReplace()
  {
  parent.oUtil.obj.setFocus();
  if(!parent.oUtil.obj.checkFocus()){return;}//Focus stuff
  var oEditor=parent.oUtil.oEditor;
  var oSel=oEditor.document.selection.createRange();

  if(oSel.text.toLowerCase()==inpSearch.value.toLowerCase())
    {
    parent.oUtil.obj.saveForUndo();
    oSel.text=inpReplace.value;
    doSearch();
    }
  else
    {
    doSearch();
    }
  parent.oUtil.obj.bookmarkSelection();
  }
var nReplaced=0;
function doReplaceAll()
  {
  parent.oUtil.obj.setFocus();
  if(!parent.oUtil.obj.checkFocus()){return;}//Focus stuff
  var oEditor=parent.oUtil.oEditor;
  var oSel=oEditor.document.selection.createRange();

  if(chkMatchCase.checked && chkMatchWord.checked) sType=6;
  else if(chkMatchCase.checked) sType=4;
  else if(chkMatchWord.checked) sType=2;
  else sType=0;

  oSel.expand("textedit");
  oSel.collapse("true");
  oSel.select();

  if(oSel.findText(inpSearch.value,1000000000,sType))
    {
    oSel.select();
    oSel.text=inpReplace.value;
    nReplaced++;
    oSel.select();
    doReplaceAll2();
    }
  else
    {
    alert(nReplaced+" occurrence(s) replaced.");
    nReplaced=0;
    return;
    }
  parent.oUtil.obj.bookmarkSelection();
  }
function doReplaceAll2()
  {
  parent.oUtil.obj.setFocus();
  if(!parent.oUtil.obj.checkFocus()){return;}//Focus stuff
  var oEditor=parent.oUtil.oEditor;
  var oSel=oEditor.document.selection.createRange();

  if(chkMatchCase.checked && chkMatchWord.checked) sType=6;
  else if(chkMatchCase.checked) sType=4;
  else if(chkMatchWord.checked) sType=2;
  else sType=0;

  oSel.collapse(false)

  if(oSel.findText(inpSearch.value,1000000000,sType))
    {
    oSel.select();
    oSel.text=inpReplace.value;
    nReplaced++;
    oSel.select();
    doReplaceAll2();
    }
  else
    {
    alert(nReplaced+" occurrence(s) replaced.");
    nReplaced=0;
    return;
    }
  parent.oUtil.obj.bookmarkSelection();
  }
function doKeyUp()
  {
  if(inpSearch.value=="")
    {
    btnSearch.disabled=true;
    btnReplace.disabled=true;
    btnReplaceAll.disabled=true;
    }
  else
    {
    btnSearch.disabled=false;
    btnReplace.disabled=false;
    btnReplaceAll.disabled=false;
    }
  }
</script>
</head>
<body style="overflow:hidden;">

<table width=100% height=100% align=center cellpadding=0 cellspacing=0>
<tr>
<td valign=top style="padding:5;height:100%">
  <table width=100%>
  <tr>
    <td nowrap><span id="txtLang" name="txtLang">Search</span>:</td>
    <td width="100%">
      <INPUT type="text" name="inpSearch" onkeyup="doKeyUp()" style="width:100%" class="inpTxt">
    </td>
    <td>
      <input type=button name=btnSearch id=btnSearch disabled value="search next" onclick="doSearch()" style="width:90" class="inpBtn" onmouseover="this.className='inpBtnOver';" onmouseout="this.className='inpBtnOut'">
    </td>
  </tr>
  <tr>
    <td nowrap><span id="txtLang" name="txtLang">Replace</span>:</td>
    <td width="100%">
      <input type="text" name="inpReplace" style="width:100%" class="inpTxt">
    </td>
    <td>
      <input type=button name=btnReplace id=btnReplace disabled value="replace" onclick="doReplace()" style="width:90" class="inpBtn" onmouseover="this.className='inpBtnOver';" onmouseout="this.className='inpBtnOut'">
    </td>
  </tr>
  <tr>
    <td nowrap colspan="2">
    <input type="checkbox" name="chkMatchCase" class="inpChk"> <span id="txtLang" name="txtLang">Match case</span>&nbsp;&nbsp;
    <input type="checkbox" name="chkMatchWord" class="inpChk"> <span id="txtLang" name="txtLang">Match whole word</span>
    </td>
    <td>
      <input type=button name=btnReplaceAll id=btnReplaceAll disabled value="replace all" onclick="parent.oUtil.obj.saveForUndo();doReplaceAll()" style="width:90" class="inpBtn" onmouseover="this.className='inpBtnOver';" onmouseout="this.className='inpBtnOut'">
    </td>
  </tr>
  <tr>
    <td colspan="2">
    </td>
    <td>
      <input type=button name=btnClose id=btnClose value="close" onclick="self.closeWin()" style="width:90" class="inpBtn" onmouseover="this.className='inpBtnOver';" onmouseout="this.className='inpBtnOut'">
    </td>
  </tr>
  </table>
</td>
</tr>
</table>

</body>
</html>